from rest_framework import serializers

from .models import *


class warning_serializer(serializers.ModelSerializer):
    class Meta:
        model = warning
        fields = "__all__"


class data_hour_serializer(serializers.ModelSerializer):
    class Meta:
        model = data_hour
        fields = "__all__"


class oil_level_serializer(serializers.ModelSerializer):
    class Meta:
        model = oil_level
        fields = "__all__"


class cb2op201_serializer(serializers.ModelSerializer):
    class Meta:
        model = cb2op201
        fields = "__all__"


class cb1op101_serializer(serializers.ModelSerializer):
    class Meta:
        model = cb1op101
        fields = "__all__"


class cb1op201_serializer(serializers.ModelSerializer):
    class Meta:
        model = cb1op201
        fields = "__all__"


class cb1op301_serializer(serializers.ModelSerializer):
    class Meta:
        model = cb1op301
        fields = "__all__"


class cb1op302_serializer(serializers.ModelSerializer):
    class Meta:
        model = cb1op302
        fields = "__all__"


class cb1op401_serializer(serializers.ModelSerializer):
    class Meta:
        model = cb1op401
        fields = "__all__"


class cb1op402_serializer(serializers.ModelSerializer):
    class Meta:
        model = cb1op402
        fields = "__all__"


class cb1op501_serializer(serializers.ModelSerializer):
    class Meta:
        model = cb1op501
        fields = "__all__"


class cb1op502_serializer(serializers.ModelSerializer):
    class Meta:
        model = cb1op502
        fields = "__all__"


class cb1op601_serializer(serializers.ModelSerializer):
    class Meta:
        model = cb1op601
        fields = "__all__"


class cb1op701_serializer(serializers.ModelSerializer):
    class Meta:
        model = cb1op701
        fields = "__all__"


class cb1op702_serializer(serializers.ModelSerializer):
    class Meta:
        model = cb1op702
        fields = "__all__"


class cb1op801_serializer(serializers.ModelSerializer):
    class Meta:
        model = cb1op801
        fields = "__all__"


class cb1op802_serializer(serializers.ModelSerializer):
    class Meta:
        model = cb1op802
        fields = "__all__"


class cb1op901_serializer(serializers.ModelSerializer):
    class Meta:
        model = cb1op901
        fields = "__all__"


class cb1op902_serializer(serializers.ModelSerializer):
    class Meta:
        model = cb1op902
        fields = "__all__"


class cb1op1001_serializer(serializers.ModelSerializer):
    class Meta:
        model = cb1op1001
        fields = "__all__"


class cb1op1002_serializer(serializers.ModelSerializer):
    class Meta:
        model = cb1op1002
        fields = "__all__"


class cb1op1101_serializer(serializers.ModelSerializer):
    class Meta:
        model = cb1op1101
        fields = "__all__"


class cb1op1102_serializer(serializers.ModelSerializer):
    class Meta:
        model = cb1op1102
        fields = "__all__"


class cb1op1201_serializer(serializers.ModelSerializer):
    class Meta:
        model = cb1op1201
        fields = "__all__"


class cb1op1202_serializer(serializers.ModelSerializer):
    class Meta:
        model = cb1op1202
        fields = "__all__"


class cb1op1701_serializer(serializers.ModelSerializer):
    class Meta:
        model = cb1op1701
        fields = "__all__"


class cb1op1702_serializer(serializers.ModelSerializer):
    class Meta:
        model = cb1op1702
        fields = "__all__"


class cb1op1801_serializer(serializers.ModelSerializer):
    class Meta:
        model = cb1op1801
        fields = "__all__"


class cb1op1802_serializer(serializers.ModelSerializer):
    class Meta:
        model = cb1op1802
        fields = "__all__"


class cb1op1901_serializer(serializers.ModelSerializer):
    class Meta:
        model = cb1op1901
        fields = "__all__"


class cb1op1902_serializer(serializers.ModelSerializer):
    class Meta:
        model = cb1op1902
        fields = "__all__"


class EphmOpInfoData_Serializer(serializers.ModelSerializer):
    class Meta:
        model = EphmOpInfoData
        fields = "__all__"


class EphmClassList_Serializer(serializers.ModelSerializer):
    class Meta:
        model = EphmClassList
        fields = "__all__"


class PowertrainOpInfo_Serializer(serializers.ModelSerializer):
    class Meta:
        model = PowertrainOpInfo
        fields = "__all__"


class PowertrainProjName_Serializer(serializers.ModelSerializer):
    class Meta:
        model = PowertrainProjName
        fields = "__all__"


class PowerEphmMeasurementPointLedger_Serializer(serializers.ModelSerializer):
    class Meta:
        model = PowerEphmMeasurementPointLedger
        fields = "__all__"


class PowerEphmPushRecords_Serializer(serializers.ModelSerializer):
    class Meta:
        model = PowerEphmPushRecords
        fields = "__all__"


class PowerEphmPushRecordsCount_Serializer(serializers.Serializer):
    zone = serializers.CharField()
    module = serializers.CharField()
    station = serializers.CharField()
    projname = serializers.CharField()
    count = serializers.IntegerField()
    latest_alarm_time = serializers.DateTimeField()
    latest_alarm_value = serializers.FloatField()
    upper_limit = serializers.FloatField()
    lower_limit = serializers.FloatField()


class PowerEphmMeasurementPointLimitUpdateSerializer(serializers.ModelSerializer):
    class Meta:
        model = PowerEphmMeasurementPointLedger
        fields = ["id", "upper_limit", "lower_limit"]


class PowerEphmManuEnterData_Serializer(serializers.ModelSerializer):
    class Meta:
        model = PowerEphmManuEnterData
        fields = "__all__"

    # def validate_datetime(self, value):
    #     """
    #     将接收到的日期时间字符串转换为标准格式。
    #     """
    #     try:
    #         # 解析原始字符串为 datetime 对象
    #         dt = parser.parse(value)
    #         # 如果是 naive 时间，则转换为 aware 时间（假定为 UTC）
    #         if timezone.is_naive(dt):
    #             dt = timezone.make_aware(dt, timezone.utc)
    #         # 转换为期望的格式字符串
    #         formatted_dt = dt.strftime("%Y-%m-%d %H:%M:%S")
    #         print("okk")
    #         return formatted_dt

    #     except ValueError as e:
    #         raise serializers.ValidationError("Invalid date time format.")

    # def create(self, validated_data):
    #     # 如果你需要在保存之前对时间进行额外处理，可以在这里做
    #     timestamp = validated_data.get("datetime")
    #     if timestamp:
    #         # 确保时间是 datetime 对象
    #         parsed_time = parser.parse(timestamp)
    #         # 更新 validated_data 中的时间戳为 datetime 对象
    #         validated_data["datetime"] = parsed_time
    #     return super().create(validated_data)




class EphmQdasBlockFeature_Serializer(serializers.ModelSerializer):
    class Meta:
        model = EphmQdasBlockFeature
        fields = "__all__"


# 用于获取item项的上下限范围,对应ephm_limits表
class EphmLimits_Serializer(serializers.ModelSerializer):
    class Meta:
        model = EphmLimits
        fields = "__all__"
        
# 对应ephm_limits_warning表
class EphmLimitsWarning_Serializer(serializers.ModelSerializer):
    class Meta:
        model = EphmLimitsWarning
        fields = "__all__"